﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Public;

namespace SalomonWebsite
{
    public partial class AdDetail : System.Web.UI.Page
    {
        public string strCon = Global.Connection;
        public string ImageWeb = Global.ImageWeb;
        public string adTitle = "";
        public string keywords = "";
        public string description = "";
        public string adContent = "";

        public int pkid;
        public int adType;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["type"] != null && Request["type"] != "" && Request["pkid"] != null && Request["pkid"] != "")
                {
                    pkid = Convert.ToInt32(Request["pkid"], CultureInfo.InvariantCulture);
                    adType = Convert.ToInt32(Request["type"], CultureInfo.InvariantCulture);
                    DataTable dtAD = Bll.CategoryAd.Single(Global.Connection, pkid);
                    if (dtAD.Rows.Count == 1)
                    {
                        if (Convert.ToInt16(dtAD.Rows[0]["AdType"]) == adType)
                        {
                            if (adType == 3 && Convert.ToDateTime(dtAD.Rows[0]["StartDate"]) <= DateTime.Now && Convert.ToDateTime(dtAD.Rows[0]["EndDate"]) >= DateTime.Now)
                            {
                                adType = Convert.ToInt16(dtAD.Rows[0]["AdType"]);
                                adTitle = dtAD.Rows[0]["AdTitle"].ToString();
                                keywords = dtAD.Rows[0]["Keywords"].ToString();
                                description = dtAD.Rows[0]["Description"].ToString();
                                adContent = dtAD.Rows[0]["AdContent"].ToString();
                                dtAD.Dispose();
                            }
                            else if (adType != 3)
                            {
                                adType = Convert.ToInt16(dtAD.Rows[0]["AdType"]);
                                adTitle = dtAD.Rows[0]["AdTitle"].ToString();
                                keywords = dtAD.Rows[0]["Keywords"].ToString();
                                description = dtAD.Rows[0]["Description"].ToString();
                                adContent = dtAD.Rows[0]["AdContent"].ToString();
                                dtAD.Dispose();
                            }
                            else
                            {
                                dtAD.Dispose();
                                Response.Redirect("FileNotFound.aspx");
                            }
                            
                        }
                        else
                        {
                            dtAD.Dispose();
                            Response.Redirect("FileNotFound.aspx");
                        }
                    }
                    else
                    {
                        dtAD.Dispose();
                        Response.Redirect("FileNotFound.aspx");
                    }
                    
                }
            }
        }
    }
}
